import Vue from 'vue';
import VueRouter from 'vue-router';
import Login from '../views/Login.vue';
import Home from '../views/Home.vue';
import Search from '../views/Search.vue';
import StoreList from '../views/StoreList.vue';
import StoreDetail from '../views/StoreDetail.vue';
import StoreComments from '../views/StoreComments.vue';

Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/home'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home
  },
  {
    path: '/search',
    component: Search
  },
  {
    path: '/store/list',
    component: StoreList
  },
  {
    path: '/store/detail',
    component: StoreDetail
  },
  {
    path: '/comments',
    component: StoreComments
  }
]

const router = new VueRouter({
  routes
});

router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    return next();
  }
  // 评论登录拦截
  /* if (to.path === '/store/comments') {
    const tokenString = window.sessionStorage.getItem('token');
    if (!tokenString) {
      return next('/login');
    }
  } */

  next();
});

export default router
